home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / raid / bitvec.c < prev    next >
C/C++ Source or Header  |  1990-10-12  |  1KB  |  69 lines

  1. /*
  2.  *
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <bstring.h>
  7. #include "bitvec.h"
  8.  
  9. BitVec
  10. MakeBitVec(n)
  11.     int n;
  12. {
  13.     BitVec vec;
  14.     int size = VecSize(n);
  15.  
  16.     vec = (BitVec) malloc((unsigned) size);
  17.     bzero((char *) vec, size);
  18.     return vec;
  19. }
  20.  
  21. void
  22. ClearBitVec(bitVec, n)
  23.     BitVec    bitVec;
  24.     int        n;
  25. {
  26.     int size = VecSize(n);
  27.     bzero((char *) bitVec, size);
  28. }
  29.  
  30. int
  31. GetBitIndex(bitVec, i, n)
  32.     BitVec bitVec;
  33.     int    i;
  34.     int    n;
  35. {
  36.     int       wordIndex;
  37.     register int   bitIndex;
  38.     register int   word;
  39.  
  40.     for (wordIndex = WordIndex(i+1); wordIndex <= WordIndex(n-1); wordIndex++){
  41.     if (bitVec[wordIndex] != 0) {
  42.         word = (unsigned) bitVec[wordIndex];
  43.         bitIndex = 0;
  44.         if (!(word & 0x0000ffff)) {
  45.         bitIndex += 16;
  46.         word = word >> 16;
  47.         }
  48.         if (!(word & 0x00ff)) {
  49.         bitIndex += 8;
  50.         word = word >> 8;
  51.         }
  52.         if (!(word & 0x0f)) {
  53.         bitIndex += 4;
  54.         word = word >> 4;
  55.         }
  56.         if (!(word & 0x03)) {
  57.         bitIndex += 2;
  58.         word = word >> 2;
  59.         }
  60.         if (!(word & 0x01)) {
  61.         bitIndex += 1;
  62.         }
  63.         ClrBit(bitVec, VecIndex(wordIndex, bitIndex));
  64.         return VecIndex(wordIndex, bitIndex);
  65.     }
  66.     }
  67.     return -1;
  68. }
  69.